﻿using Gargoyle.Roton;
using System;
using System.Collections.Generic;
using System.Text;

namespace Gargoyle.ZZT
{
    public class Thing
    {
        private ByteString internalCode;

        public Int16 Cycle;
        public Int16 Follower;
        public Int16 Instruction;
        public Int16 Leader;
        public Int16 Length;
        public Location Location;
        public byte[] Parameter = new byte[3];
        public Tile UnderTile;
        public Vector Vector;

        public Thing Clone()
        {
            return (Thing)MemberwiseClone();
        }

        public ByteString Code
        {
            get
            {
                return internalCode;
            }
            set
            {
                internalCode = value;
            }
        }

        public void CopyFrom(Thing source)
        {
            Code = source.Code;
            Cycle = source.Cycle;
            Follower = source.Follower;
            Instruction = source.Instruction;
            Leader = source.Leader;
            Length = source.Length;
            Location = source.Location;
            P1 = source.P1;
            P2 = source.P2;
            P3 = source.P3;
            UnderTile = source.UnderTile;
            Vector = source.Vector;
        }

        public byte P1
        {
            get
            {
                return Parameter[0];
            }
            set
            {
                Parameter[0] = value;
            }
        }

        public byte P2
        {
            get
            {
                return Parameter[1];
            }
            set
            {
                Parameter[1] = value;
            }
        }

        public byte P3
        {
            get
            {
                return Parameter[2];
            }
            set
            {
                Parameter[2] = value;
            }
        }

        public override string ToString()
        {
            return "Thing (X=" + Location.X + ", Y=" + Location.Y + ")";
        }

        public byte X
        {
            get
            {
                return Location.X;
            }
            set
            {
                Location.X = value;
            }
        }

        public Int16 XStep
        {
            get
            {
                return Vector.X;
            }
            set
            {
                Vector.X = value;
            }
        }

        public byte Y
        {
            get
            {
                return Location.Y;
            }
            set
            {
                Location.Y = value;
            }
        }

        public Int16 YStep
        {
            get
            {
                return Vector.Y;
            }
            set
            {
                Vector.Y = value;
            }
        }
    }
}
